package com.timoon.sample.web.role;


import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.spring.injection.annot.SpringBean;

import com.googlecode.wicket.jquery.ui.Options;
import com.timoon.app.utils.Constantor;
import com.timoon.component.panel.jqgrid.JqGridPanel;
import com.timoon.component.panel.jqgrid.JqGridService;
import com.timoon.component.panel.jqgrid.panel.CreatorPanel;
import com.timoon.component.panel.nav.ResourceMapper;
import com.timoon.sample.web.role.panel.RoleCreatorPanel;

public class RoleJqGridPanel extends Panel {
	private static final long serialVersionUID = 4267085589714931630L;

	@SpringBean(name="com.flt.sample.role.RoleJqGridServiceImpl")
	private JqGridService service;
	
	private JqGridPanel grid;
	
	public RoleJqGridPanel(String id) {
		super(id);
		// TODO Auto-generated constructor stub
		Options ops=new Options();
		ops.set("colModel", "[" +
				"{name:'id',index:'id',label:'ID'}," +
				"{name:'text',index:'text',label:'名称'}," +
				"{name:'statusText',index:'statusText',label:'状态'}," +
				"{name:'remark',index:'remark',label:'备注'}," +
				"]");
		grid=new JqGridPanel("wk_role_grid", ops, service,null){
			@Override
			public CreatorPanel getCreatorPanel(String id, JqGridPanel mainPanel,String recordId) {
				// TODO Auto-generated method stub
				return new RoleCreatorPanel(id, mainPanel,recordId);
			}
			@Override
			public boolean isButtonVisible(String buttonName) {
				// TODO Auto-generated method stub
				ResourceMapper mapper=(ResourceMapper) this.getSession().getAttribute(Constantor.SESSION_USER_MAPPER);
				boolean visible=false;
				if(buttonName.equals(JqGridPanel.ADD_BUTTON_ENABEL)){
					return mapper.getResourceMap().containsKey("role_manager_add_button");
				}else if(buttonName.equals(JqGridPanel.DELETE_BUTTON_ENABLE)){
					return mapper.getResourceMap().containsKey("role_manager_delete_button");
				}else if(buttonName.equals(JqGridPanel.MODIFIER_BUTTON_ENABLE)){
					return mapper.getResourceMap().containsKey("role_manager_modifier_button");
				}else if(buttonName.equals(JqGridPanel.DETAIL_BUTTON_ENABLE)){
					return mapper.getResourceMap().containsKey("role_manager_detail_button");
				}
				
				return visible;
			}
		};
		
		add(grid);
		
		
	}

	public JqGridService getService() {
		return service;
	}

	public void setService(JqGridService service) {
		this.service = service;
	}

}
